package com.aat.dxfy.redis.test.keycount;

import redis.clients.jedis.Jedis;

public class TaskProducer implements Runnable {
	private Jedis jedis;

	public TaskProducer(Jedis jedis) {
		this.jedis = jedis;
	}

	public void run() {
		while (true) {
			try {
				// 模拟生成一个任务
				String[] keys = { "1", "2", "3" };
				int index = (int) (Math.random() * keys.length);
				String key = keys[index];
				try {
					int ss = (int) (Math.random() * 3000 + 1000);
					Thread.sleep(ss);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

				// 将任务插入任务队列：task-queue
				jedis.lpush("task-queue", key);

				System.out.println("插入了一个新的任务： " + key);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}